package com.rjwh.dingdong.client.util;

import java.util.Stack;

import android.app.Activity;

public class ScreenManger {
	private static Stack activitystack;
	private static ScreenManger intance;

	public static ScreenManger getScreenManger() {
		intance = new ScreenManger();
		activitystack = new Stack();
		return intance;
	}

	public void popactivity(Activity activity) {
		activity.finish();
		activitystack.remove(activity);
		activity = null;
//		System.out.println("in-out");
	}

	public Activity currentactivity() {
		if (activitystack.empty()) {
			return null;
		} else {
			Activity activity = (Activity) activitystack.lastElement();
			return activity;
		}
	}

	public void pushactivity(Activity activity) {
//		System.out.println("in-in");
		activitystack.add(activity);
	}

	public void popallactivityexceptone() {
              
		boolean exit = false;
		while (!exit) {
			Activity activity = currentactivity();
			if (activity != null) {
				exit = false;
				popactivity(activity);
			} else {
				exit = true;
			}
		}
	}

	public void popallactivityexceptone1() {
		boolean exit = false;
		while (!exit) {
			Activity activity = currentactivity();
			if (activity != null) {
				exit = false;
				popactivity(activity);
			} else {
				exit = true;
			}
		}
	}	
}
